package com.logansoft.servicehomework.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liqiye
 * @description 分布式锁 redission 的配置
 * @date 2021/7/16
 */

@Configuration
public class RedissonConfig {

    /**
     * 通过RedissonClient对象来使用分布式锁
     */
    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson() {
        //1 创建配置
        Config config = new Config();
        config.useSingleServer().setAddress("redis://localhost:6379");

        //2 根据Config创建出RedissonClient实例
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
